﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
    <title>Modifica scheduler</title>
    <script type="text/javascript">
        var length = 0;
        var xmldoc = null;
        function checkField(input) {
            if (input.value.length == 0) {
                alert("I campi non devono essere vuoti!");
                input.setActive();
            }
        }

        function saveFile() {
            var day = "";
            if (window.DOMParser) {
                for (var i = 1; i < length; i=i+2) {
                    day = document.getElementById("tbClass" + i).value;
                    xmldoc.childNodes[0].childNodes[i].childNodes[3].textContent = day;
            }   
                document.getElementsByName("tbHidPath")[0].value = document.getElementById("tbFile").value;
                document.getElementsByName("tbHidFile")[0].value = new XMLSerializer().serializeToString(xmldoc);
            }
            else {
                for (var i = 0; i < length; i++) {
                    day = document.getElementById("tbClass" + i).value;
                    xmldoc.childNodes[0].childNodes[i].childNodes[1].text = day;
                }
                    document.getElementById("tbHidPath").value = document.getElementById("tbFile").value;
                    document.getElementById("tbHidFile").value = xmldoc.xml;
            }
            document.myForm.submit();
        }

        function read() {
            var classes = new Array();      //array contenenti nomi delle classi
            var days = new Array();         //array conentenete giorni

            var postRequest = new XMLHttpRequest();
            postRequest.open("POST", "http://localhost:2703/GetXMLDocument", false);
            postRequest.setRequestHeader("Path", document.getElementById("tbFile").value);
            postRequest.send(null);

            if (window.DOMParser) {
                parser = new DOMParser();

                xmldoc = parser.parseFromString(postRequest.responseText, "text/xml");
                xmldoc.async = "false";

                document.getElementById("xml").innerHTML = "";

                length = xmldoc.childNodes[0].childNodes.length;
                for (var i = 1; i < length; i = i + 2) {
                    classes[i] = xmldoc.childNodes[0].childNodes[i].attributes[0].value.replace("Win32_", "");
                    days[i] = xmldoc.childNodes[0].childNodes[i].childNodes[3].textContent;
                }

                for (var i = 1; i < classes.length; i = i + 2) {
                    document.getElementById("xml").innerHTML += "<div id=\"line\"><div id=\"divName" + i + "\" class=\"divName\"></div><div id=\"divDay" + i + "\" class=\"divDay\"></div></div><br/><br/>";
                    document.getElementById("divName" + i).innerHTML += classes[i];
                    document.getElementById("divDay" + i).innerHTML += "<input type=\"text\" value=\"" + days[i] + "\" size=\"2\" id=\"tbClass" + i + "\" onBlur=\"checkField(this)\"/><br/>";

                }

            }
            else {
                xmldoc = new ActiveXObject("Microsoft.XMLDOM");
                xmldoc.async = "false";
                xmldoc.loadXML(postRequest.responseText);

                document.getElementById("xml").innerHTML = "";
                //xmlPath = document.getElementById("tbFile").value;

                length = xmldoc.childNodes[1].childNodes.length;
                for (var i = 0; i < length; i++) {
                    classes[i] = xmldoc.childNodes[1].childNodes[i].attributes.getNamedItem("name").nodeValue.replace("Win32_", "");
                    days[i] = xmldoc.childNodes[1].childNodes[i].childNodes[1].text;
                }

                for (var i = 0; i < classes.length; i++) {
                    document.getElementById("xml").innerHTML += "<div id=\"line\"><div id=\"divName" + i + "\" class=\"divName\"></div><div id=\"divDay" + i + "\" class=\"divDay\"></div></div><br/><br/>";
                    document.getElementById("divName" + i).innerHTML += classes[i];
                    document.getElementById("divDay" + i).innerHTML += "<input type=\"text\" value=\"" + days[i] + "\" size=\"2\" id=\"tbClass" + i + "\" onBlur=\"checkField(this)\"/><br/>";

                    document.getElementById("btSnd").disabled = "";
                }

            }
            document.getElementById("btSnd").disabled = "";
        }

    </script>
    <style type="text/css">
        #tbFile
        {
            width: 543px;
        }
        .divName
        {
            float: left;
            width: 220px;
        }
        .divDay
        {
            float: left;
            width: 10px;
        }
        #xml
        {
            margin-left: 15px;
        }
        #content
        {
            font-size: 0.7em;
            padding-bottom: 2em;
            margin-left: 30px;
        }
        body
        {
            margin-top: 0px;
            margin-left: 0px;
            color: #000000;
            font-family: Verdana;
            background-color: white;
        }
        p
        {
            margin-top: 0px;
            margin-bottom: 12px;
            color: #000000;
            font-family: Verdana;
        }
        pre
        {
            border-right: #f0f0e0 1px solid;
            padding-right: 5px;
            border-top: #f0f0e0 1px solid;
            margin-top: -5px;
            padding-left: 5px;
            font-size: 1.2em;
            padding-bottom: 5px;
            border-left: #f0f0e0 1px solid;
            padding-top: 5px;
            border-bottom: #f0f0e0 1px solid;
            font-family: Courier New;
            background-color: #e5e5cc;
        }
        .heading1
        {
            margin-top: 0px;
            padding-left: 15px;
            font-weight: normal;
            font-size: 26px;
            margin-bottom: 0px;
            padding-bottom: 3px;
            margin-left: -30px;
            width: 100%;
            color: #ffffff;
            padding-top: 10px;
            font-family: Tahoma;
            background-color: #003366;
        }
    </style>
</head>
<body>
    <div id="content">
        <p class="heading1">
            Mynte</p>
        <br />
            <p>
                Inserire percorso file Scheduler.xml:<br />
                <input type="text" value="C:\Program Files (x86)\Mynte\Scheduler.xml" id="tbFile" />
                <input id="btOK" type="button" value="OK" onclick="read()" />
                <br />
            </p>
        
    <div id="xml">
    </div>
        <form name="myForm" action="http://localhost:2703\SaveXML" method="POST" enctype="text/Xml">
            <input type="hidden" name="tbHidPath"/>
            <input type="hidden" name="tbHidFile"/>
            <p>
                <input id="btSnd" type="button" value="Save" onclick="saveFile()" disabled="disabled" />
            </p>
        </form>
    </div>
</body>
</html>
